package com.lwj.liwanjia.adapter.indent;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.lwj.liwanjia.R;
import com.lwj.liwanjia.bean.TkdetailBean;

import java.text.SimpleDateFormat;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/10/23.
 */

public class TkAdapter extends RecyclerView.Adapter<TkAdapter.MyViewHolder> {

    private Context context;
    private List<TkdetailBean.DataBean.ProcessBean> list;
    private LayoutInflater inflater;

    public TkAdapter(Context context, List<TkdetailBean.DataBean.ProcessBean> list) {
        this.context = context;
        this.list = list;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.tk_item, parent, false);
        MyViewHolder holder = new MyViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        if (position == 0) {
            holder.ivStatus.setImageResource(R.mipmap.yuandian_1);
            holder.tvStatus.setTextColor(context.getResources().getColor(R.color.colorEC921A));
        } else {
            holder.ivStatus.setImageResource(R.mipmap.yuandian);
            holder.tvStatus.setTextColor(Color.GRAY);
        }
        if (position == list.size() - 1) {
            holder.line.setVisibility(View.GONE);
        } else {
            holder.line.setVisibility(View.VISIBLE);
        }
        holder.tvStatus.setText(list.get(position).getTitle());
        holder.tvInfor.setText(list.get(position).getContent());
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        long time1 = list.get(position).getTime();
        if (time1 != 0) {
            String date = dateFormat.format(time1);
            holder.tvTime.setText(date);
            holder.tvTime.setVisibility(View.VISIBLE);
        } else {
            holder.tvTime.setVisibility(View.GONE);
        }
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.iv_status)
        ImageView ivStatus;
        @BindView(R.id.line)
        View line;
        @BindView(R.id.tv_status)
        TextView tvStatus;
        @BindView(R.id.tv_infor)
        TextView tvInfor;
        @BindView(R.id.tv_time)
        TextView tvTime;

        public MyViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
